<?php
/*
 * 手机客户端 测试文件上传
 * 2013-12-14
 */
include "inc/public_header.php";

include "func/user.php";				//用户信息处理函数

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array(
		 "success"=>"0"
		,"errCode"=>"0"
		,"msg"=>"没有获取到用户信息"
		,"uuid"=>$_REQUEST["uuid"]));
	die;
}
$uid = $uInfoArr["uid"]; //用户信息主键


//图片根路径
$BASE_UPLOAD_PATH = "/img1/uploads/zjl_ilogo/"; 
//图片显示根路径
$SHOW_IMG_BASE_URL = "http://www.chinalaohu.com/img1/uploads/zjl_ilogo/";

$uploadOK 		= false; 	//是否上传成功
$zuopinId 		= "";		//作品主键
$fImgPath 		= ""; 		//第一张图片文件名
$fImgId 		= ""; 		//第一张图片信息主键
$reUrl 			= array(); 	//返回图片url
$oldNames 		= "";		//上传的文件原名序列
$newNames		= "";		//上传后的文件名序列
$upFileCount	= 0;
foreach((array)$_FILES['img_file']['tmp_name'] as $k=>$v){
	if($_FILES['img_file']['name'][$k]!=""){
		$tmpPath = $_FILES['img_file']['tmp_name'][$k];
		$oldFileName = basename($_FILES['img_file']['name'][$k]);
		$extName = explode(".",$oldFileName);
		$extName = $extName[count($extName)-1];
		$newFileName = $uid."_".date("YmdHms")."_".$k."_".".".$extName;
		if($oldNames==""){
			$oldNames = $oldFileName;
		}else{
			$oldNames = $oldNames.",".$oldFileName;
		}
		$upFileCount++;
		if(!$oldFileName){
			continue;
		}
		
		if(strtolower($extName)!="jpg" && strtolower($extName)!="jpeg"){
			
			echo json_encode(array("success"=>"0","errCode"=>"1","msg"=>"上传的图片只能是jpg/jpeg格式(".$oldFileName.")"));
			die;
		}
		if($newNames==""){
			$newNames = $newFileName;
		}else{
			$newNames = $newNames.",".$newFileName;
		}
		$uploaddir =$BASE_UPLOAD_PATH;

		if(move_uploaded_file($tmpPath,$uploaddir.$newFileName)){
			/*
			 * 上传成功，处理语句信息
			 */
			  $uploadOK=true;
			$sql="update new_weituo_person set ilogo_path='".$newNames."' where uid='".$uid."'";
			$db->query($sql);
			
			 $reUrl[] = $SHOW_IMG_BASE_URL.$newFileName;			
		}
	}
}
echo json_encode($uploadOK);
if($uploadOK){
echo json_encode(array(
		"success"=>"1"
		,"old_file_names"=>$oldNames
		,"new_file_names"=>$newNames
		,"upload_files_count"=>(string)$upFileCount
		,"imgUrls"=>$reUrl[0]));
}else{
	echo json_encode(array("success"=>"0","errCode"=>"2"));
}
die;
?>